﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EAS.Data.Access;
using EAS.Services;
using EAS.Data.ORM;

namespace HR.WinUI
{
    public partial class BaseUserControl : UserControl
    {
        public BaseUserControl()
        {
            InitializeComponent();

        }

        public EAS.Data.Access.IDataAccessor DataAccessor
        {
            get
            {
                return EAS.Context.ContextHelper.GetContext().Container.GetComponentInstance("DataAccessor") as EAS.Data.Access.IDataAccessor;
            }
        }

        #region 报表相关

        EAS.Explorer.Entities.Report report;

        ///// <summary>
        ///// 报表。
        ///// </summary>
        //protected EAS.Explorer.Entities.Report Report
        //{
        //    get
        //    {
        //        if (this.report == null)
        //        {
        //            this.report = new EAS.Explorer.Entities.Report();
        //            this.report.Name = string.Empty;
        //        }
        //        return this.report;
        //    }
        //}


        //EAS.Report.Controls.PrintViewDialog printForm;
        ///// <summary>
        ///// 打印窗体。
        ///// </summary>
        //protected EAS.Report.Controls.PrintViewDialog PrintForm
        //{
        //    get
        //    {
        //        if (this.printForm == null)
        //        {
        //            this.printForm = new EAS.Report.Controls.PrintViewDialog();
        //        }
        //        return this.printForm;
        //    }
        //}

        /// <summary>
        /// 打印预览方法
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="dataSource">实体集合</param>
        //protected void PrintPreview<T>(IList<T> dataSource)
        //{
        //    if (dataSource == null || dataSource.Count < 1)
        //        return;

        //    if (this.Report.Name == null || this.Report.Name.Trim() == string.Empty)
        //        return;

        //    this.Report.Refresh();

        //    if (!this.Report.Exists)
        //    {
        //        MessageBox.Show("没有找到'" + this.Report.Name + "' 报表的定义。\n请联系系统管理员，确认该报表的创建。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        //        return;
        //    }

        //    this.PrintForm.Report = this.Report;
        //    this.PrintForm.DataObject = dataSource;
        //    this.PrintForm.PrintPreview();
        //}

        /// <summary>
        /// 直接打印方法
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="dataSource">实体集合</param>
        //protected void Print<T>(IList<T> dataSource)
        //{
        //    if (dataSource == null || dataSource.Count < 1)
        //        return;

        //    if (this.Report.Name == null || this.Report.Name.Trim() == string.Empty)
        //        return;

        //    this.Report.Refresh();

        //    if (!this.Report.Exists)
        //    {
        //        MessageBox.Show(" 不存在报表 '" + this.Report.Name + "' 的定义文件，请联系管理员创建该报表定义！");
        //        return;
        //    }

        //    this.PrintForm.Report = this.Report;
        //    this.PrintForm.DataObject = dataSource;
        //    this.PrintForm.Print();
        //}

        #endregion

        #region 进入\退出 控件焦点

        public void Control_Enter(object sender, EventArgs e)
        {
            System.Windows.Forms.Control ctrl = sender as System.Windows.Forms.Control;

            ctrl.BackColor = System.Drawing.Color.FromArgb(0xC0, 0xFF, 0xC0);
            ctrl.ForeColor = System.Drawing.Color.Red;

            if (ctrl is System.Windows.Forms.ComboBox)
            {
                ((System.Windows.Forms.ComboBox)ctrl).DroppedDown = true;
            }
            else if (ctrl is System.Windows.Forms.TextBox)
            {
                ((System.Windows.Forms.TextBox)ctrl).SelectAll();
            }
        }

        public void Control_Leave(object sender, EventArgs e)
        {
            System.Windows.Forms.Control ctrl = sender as System.Windows.Forms.Control;

            ctrl.BackColor = System.Drawing.Color.White;
            ctrl.ForeColor = System.Drawing.Color.Black;
            RegularExpressions(ctrl.Name);
        }
        public virtual void RegularExpressions(string name)
        {

        }

        #endregion

        //#region 获取系统时间设置相关

        //public DateTime CurrentTime
        //{
        //    //get
        //    //{
        //    //    return ServiceContainer.GetService<HR.BLL.IDateTimeService>().GetCurrentTime();
        //    //}
        //}

        //public DateTime MinTime
        //{
        //    //get
        //    //{
        //    //    return ServiceContainer.GetService<HR.BLL.IDateTimeService>().GetMinTime();
        //    //}
        //}

        //#endregion

        #region 遍历清空
        #region 遍历清空
        public void clear_text()
        {
            foreach (System.Windows.Forms.Control ctrl in this.Controls)
                if (ctrl.Controls.Count > 0)
                {
                    foreach (System.Windows.Forms.Control ctr in ctrl.Controls)
                        if (ctr is System.Windows.Forms.TextBox)
                            ctr.Text = "";
                }
        }

        #endregion
        #endregion
    }

}
